package com.kgc.scd.service.impl;

import com.kgc.scd.bean.Product;
import com.kgc.scd.bean.ProductExample;
import com.kgc.scd.mapper.CollectMapper;
import com.kgc.scd.mapper.ProductMapperJzp;
import com.kgc.scd.service.GuessUserLikeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created On : 2022/6/13.
 * <p>
 * Author     : 98730
 * <p>
 * Description: 猜你喜欢业务实现类
 */
@Slf4j
@Service
public class GuessUserLikeServiceImpl implements GuessUserLikeService {

    @Autowired(required = false)
    private CollectMapper collectMapper;

    @Autowired(required = false)
    private ProductMapperJzp productMapperJzp;

    /**
     * @author : 98730
     * @date   : 2022/6/13
     * @param  : [java.lang.String]
     * @return : java.util.List<com.kgc.scd.bean.Product>
     * @description : 根据用户喜欢商品，查询商品类型id
     */
    @Override
    public List<Product> queryCollectListByUser(String userId) {
        log.info("进入queryCollectListByUser");
        // 根据用户喜欢商品，查询商品类型
        List<Integer> cids = collectMapper.selectCidByUserId(userId);
        log.info("cids:{}",cids);
        List<Product> productList = new ArrayList<>();

        if (cids.isEmpty()){
            return productList;
        }
        ProductExample productExample = new ProductExample();
        ProductExample.Criteria criteria = productExample.createCriteria();
        for (Integer cid : cids){
            criteria.andProCategoryidEqualTo(cid);
        }

        log.info("*****List:{}",productMapperJzp.selectByExample(productExample));
        return productMapperJzp.selectByExample(productExample);
    }

    @Override
    public List<Product> queryFootListByUser(String userId) {
        log.info("进入queryFootListByUser");
        List<Integer> cids = collectMapper.selectFootCidByUserId(userId);
        log.info("cids:{}",cids);
        List<Product> productList = new ArrayList<>();

        if (cids.isEmpty()){
            return productList;
        }
        ProductExample productExample = new ProductExample();
        ProductExample.Criteria criteria = productExample.createCriteria();
        for (Integer cid : cids){
            criteria.andProCategoryidEqualTo(cid);
        }
        return productMapperJzp.selectByExample(productExample);
    }

    @Override
    public List<Product> queryAllProduct() {
        ProductExample productExample = new ProductExample();
        return productMapperJzp.selectByExample(productExample);
    }

}
